﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FantastPlatform.Framework.Service;
using FantastPlatform.Framework;
using NHibernate;
using NHibernate.Criterion;
using FantastPlatform.Decision.IModel;
using FantastPlatform.Decision.Model;
using FantastPlatform.Decision.IService;

namespace FantastPlatform.Decision.Service
{
    public class MeetingService : DataService<IMeeting, Meeting>, IMeetingService
    {

        public IList<IMeeting> SearchMeet(int policeId)
        {
            ICriteria criteria = Session.CreateCriteria(typeof(Meeting));
            criteria.Add(Expression.Gt("MeetingDate", DateTime.Now)).Add(Expression.Eq("Enable", true))
                .CreateCriteria("Persons", "p").Add(Expression.Eq("p.Id", policeId));
            criteria.AddOrder(Order.Desc("CreateDate"));
            return criteria.List<IMeeting>();
        }


        public IList<IMeeting> SearchMeet(string code)
        {
            ICriteria criteria = Session.CreateCriteria(typeof(Meeting));
            criteria.Add(Expression.Gt("MeetingDate", DateTime.Now)).Add(Expression.Eq("Enable", true))
                .CreateCriteria("Persons", "p").Add(Expression.Eq("p.Code", code));
            criteria.AddOrder(Order.Desc("CreateDate"));
            return criteria.List<IMeeting>();
        }
    }
}
